package com.atcumt.xiaoyuan;

import java.util.Scanner;

public class HJOD04 {

    /**
     * 6
     * 1 -1 -6 7 -17 7
     * 2
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] scores = new int[n];
        for (int i = 0; i < n; i++) {
            scores[i] = scanner.nextInt();
        }
        int k = scanner.nextInt();
        int maxLen = getMaxLen(scores, k);
        System.out.println(maxLen);
    }
    
    public static int getMaxLen(int[] score, int k) {
        int n = score.length;
        int[] dp = new int[n];
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return score[0];
        }
        dp[0] = score[0];
        for (int i = 1; i < n; i++) {
            int max = Integer.MIN_VALUE;
            for (int j = 1; j <= k && i - j >=0; j++) {
                max = Math.max(max, dp[i - j]);
            }
            dp[i] = max + score[i];
        }
        return dp[n - 1];
    }
}
